<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clearList"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        label="会员信息"
        min-width="200"
        prop="memberInfo"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="学员姓名"
        min-width="80"
        prop="studentName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="原课程名称"
        min-width="120"
        prop="oldCourseName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="课程类型"
        prop="courseType"
        min-width="100"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <span v-if="scope.row.courseType == '1'">团体课</span>
          <span v-if="scope.row.courseType == '3'">长期课</span>
          <span v-if="scope.row.courseType == '4'">私教课</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="课程价格"
        prop="price"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="总课时数"
        prop="num"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="已换课程"
        prop="newCourseName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="状态"
        prop="status"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作时间"
        prop="createTime"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作人"
        prop="creator"
        min-width="100"
        show-overflow-tooltip
      />
    </el-table>
    <Paginations
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import { courseChangeRecord } from '@/api'
import { queryFormConfig } from './config'
import QueryForm from '@/components/QueryForm'
export default {
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig,
      meta: [],
      list: [],
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      payList: [
        { value: '01', label: '会员卡' },
        { value: '02', label: '现金' },
        { value: '03', label: '微信' },
        { value: '04', label: '支付宝' }
      ],
      filters: {},
      listLoading: true,
      allPayMethedList: []
    }
  },
  created() {
    this.getList(1)
  },
  mounted() {
    this.$refs.table.doLayout()
  },
  methods: {
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    clearList() {
      this.filters = {}
      this.getList(1)
    },
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      courseChangeRecord({ pagination, param: { venueId, ...filters }})
        .then(res => {
          this.listLoading = false
          this.list = res.recordList || []
          this.total = res.totalCount
        })
        .catch(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
